<script src="{{ getAssets }}js/amazeui.datatables.min.js?v={{ assets_version }}"></script>
<script>
var typeid = '{{.typeid}}';
var product_id = '{{.product_id}}';
var columns = [{"data" : "id", "sWidth":"50px", "bSortable": false, "sTitle":'<input type="checkbox" class="selectAll"/>', render:function (data, type, full, meta) {
		return '<input type="checkbox" class="selectOne" data-row="'+ meta.row +'" value="'+ full.id +'" />';
    }}];
switch (typeid) {
    case '10':
        columns.push({"data" : "sph", "bSortable": false, "sTitle":"球镜"});
        columns.push({"data" : "cyl", "bSortable": false, "sTitle":"柱镜"});
        $('#search_key').attr('placeholder', '球镜、柱镜');
        break;
    case '20':
        columns.push({"data" : "sph", "bSortable": false, "sTitle":"球镜"});
        columns.push({"data" : "cyl", "bSortable": false, "sTitle":"柱镜"});
        $('#search_key').attr('placeholder', '球镜、柱镜');
        break;
    case '30':
        columns.push({"data" : "model", "bSortable": false, "sTitle":"型号"});
        columns.push({"data" : "color", "bSortable": false, "sTitle":"色号"});
        columns.push({"data" : "size", "bSortable": false, "sTitle":"尺寸"});
        columns.push({"data" : "genre", "bSortable": false, "sTitle":"框型"});
        $('#search_key').attr('placeholder', '型号、色号、尺寸');
        break;
    case '40':
        columns.push({"data" : "sph", "bSortable": false, "sTitle":"球镜"});
        columns.push({"data" : "add", "bSortable": false, "sTitle":"ADD"});
        $('#search_key').attr('placeholder', '球镜、ADD');
        break;
    case '41':
        columns.push({"data" : "model", "bSortable": false, "sTitle":"型号"});
        columns.push({"data" : "color", "bSortable": false, "sTitle":"色号"});
        columns.push({"data" : "size", "bSortable": false, "sTitle":"尺寸"});
        columns.push({"data" : "film_color", "bSortable": false, "sTitle":"膜层颜色"});
        columns.push({"data" : "function_info", "bSortable": false, "sTitle":"功效"});
        columns.push({"data" : "genre", "bSortable": false, "sTitle":"框型"});
        $('#search_key').attr('placeholder', '型号、色号、尺寸');
        break;
    case '70':
        columns.push({"data" : "norms", "bSortable": false, "sTitle":"规格"});
        columns.push({"data" : "place_origin", "bSortable": false, "sTitle":"产地"});
        columns.push({"data" : "dnumber", "bSortable": false, "sTitle":"批准文号"});
        $('#search_key').attr('placeholder', '规格、产地、批准文号');
}

var tables = $('#dataTables').DataTable({
    "sAjaxSource" : location.href
    ,"bLengthChange": false
    ,"fnServerData" : function(sSource, aoData, fnCallback) {
        var params = checkQueryTableData(aoData);
        $('#search_key').val() ? params.filter = $('#search_key').val() : '';
		params.typeid = typeid;
        $.post(sSource, JSON.stringify(params),function(resp) {
            fnCallback(resp);
        },'json')
    }
    ,order:[]
    ,columns: columns
    ,"aLengthMenu":[20, 50, 100, 200]
    ,'bLengthChange': true
    ,"serverSide": true
    ,"bPaginate" : true
    ,"bFilter" : false	//是否启动过滤、搜索功能
    ,"bInfo" : true //是否显示页脚信息，DataTables插件左下角显示记录数
    ,"bProcessing" : true //DataTables载入数据时，是否显示‘进度’提示
});

$("#searchsubmit").bind("click", function () { //点击按钮 触发table重新请求服务器
    $("#dataTables").dataTable().fnDraw(false);
});

$('.selectAll').click(function(){
    if($(this).prop('checked') != false) {
        $('.selectOne').prop('checked', true);
    } else {
        $('.selectOne').prop('checked', false);
    }
});


$('#selectYes').click(function(){
   var selLine = $('.selectOne[type="checkbox"]:checked');
   if(selLine.length <= 0) {
     layer.alert("请选择需要的行");return false;
   }
   var _data = [];
   $.each(selLine, function(){
	   var row = $(this).data('row');
	   var data = tables.row( row ).data();
	   _data.push(data);
   });
   parent.setSelectSndLine(_data);
   parent.layer.closeAll('iframe');
});
//批量停用
$('#closeWin').click(function(){
   parent.layer.closeAll('iframe');
});

function dialogReback() {
    tables.ajax.reload();
}
</script>